package cn.wit.test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoRequest extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
		String name = req.getParameter("name");
		
		System.out.println(name);
		
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		String name = req.getParameter("User");
		
		//将字符变成字节
		//name(User) = %E5%BC%A0%E4%B8%89
		//这里如果不按照iso-889-1来，就恢复不到原来字节
		//原来字节：-27 -68 -96
		byte[] names = name.getBytes("iso-8859-1");
		
		//将字节重新编码成字符
		String s3 = new String(names,"utf-8");
		
		System.out.println(s3);
		
		//把参数封装到请求头里面的时候，会按我们设置的utf-8来进行编码
		//就不会按照之前的iso-8859-1的编码进行封装
//		req.setCharacterEncoding("utf-8");
//		
//		System.out.println(req.getParameter("User"));
			
	}

}
